package com.gb.demand.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gb.demand.common.api.ResultMap;
import com.gb.demand.common.dto.GoodsBO;
import com.gb.demand.common.entity.Accessory;
import com.gb.demand.common.entity.Apilog;
import com.gb.demand.common.entity.Goods;
import com.gb.demand.common.entity.Store;
import com.gb.demand.common.mapper.GoodsMapper;
import com.gb.demand.service.IApilogService;
import com.gb.demand.service.IGoodsService;
import com.gb.demand.service.IStoreService;
import com.gb.demand.service.IUsergoodsclassService;
import com.gb.demand.service.ex.MyEx.GoodsException;
import com.gb.demand.service.ex.ServiceException;
import com.gb.demand.util.JsonUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 用户业务层模块<p>
 *
 * @author wengjiangle
 * @since 2020/7/13
 */
@Slf4j
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Autowired
    private IApilogService apilogService;

    @Autowired
    private GoodsMapper goodsMapper;

    /**
     * 日志记录
     *
     * @param caller      调用者
     * @param inputvalue  输入参数
     * @param outputvalue 输出参数
     * @param remark      备注
     */
    private void addApiLog(String caller, String inputvalue, String outputvalue, String remark) {
        // 记录调用日志
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        Apilog apilog = new Apilog(new Date(), false, "", request.getRequestURL().toString(), caller, inputvalue, outputvalue, remark);
        apilogService.save(apilog);
    }

    @Override
    public List<GoodsBO> getGoodsAll() {
        return goodsMapper.getGoodsAll();
    }
}
